class AverageMeter(object):
    """Computes and stores the average and current value"""
    def __init__(self, name, fmt=':f'):
        self.name = name
        self.fmt = fmt
        self.reset()

    def reset(self):
        self.val = 0
        self.avg = 0
        self.sum = 0
        self.count = 0

    def update(self, val, n=1):
        self.val = val
        self.sum += val * n
        self.count += n
        self.avg = self.sum / self.count

    def __str__(self):
        return f'{self.name} {self.avg}'

class MovingAverageMeter:
    def __init__(self, name, fmt=':f', gamma=0.9):
        self.name = name
        self.fmt = fmt
        self.gamma = gamma

        self.avg = 0
        self.reset()

    def reset(self):
        self.avg = 0

    def update(self, val, n=1):
        self.avg = self.avg * self.gamma + val * (1 - self.gamma)

    def __str__(self):
        return f'{self.name} {self.avg}'
